// 引入Count的UI组件
import CountUI from "../../components/Count";

//引入connect用于连接UI组件和redux
import { connect } from 'react-redux'
// 引入action
import { createIncrementAction, createDecrementAction, createIncrementAsyncAction } from '../../redux/count_action_creators'

// // 映射状态
// const mapStateToProps = state => ({ count: state })

// // 映射操作状态的方法
// const mapDispatchToProps = dispatch => ( {
//   // 通知redux执行加法
//   jia: (number) => dispatch(createIncrementAction(number)),
//   jian: (number) => dispatch(createDecrementAction(number)),
//   jiaAsync: (number, time) => dispatch(createIncrementAsyncAction(number, time))
// })

// 使用connect创建并暴露一个Count的容器组件
// export default connect(mapStateToProps, mapDispatchToProps)(CountUI)
export default connect(
  state => ({ count: state }),
  // mapDispatchToProps的一般写法(函数)
  /* dispatch => ({
      // 通知redux执行加法
      jia: (number) => dispatch(createIncrementAction(number)),
      jian: (number) => dispatch(createDecrementAction(number)),
      jiaAsync: (number, time) => dispatch(createIncrementAsyncAction(number, time))
    }) */
  // mapDispatchToProps的简写（对象）
  {
    jia: createIncrementAction,
    jian: createDecrementAction,
    jiaAsync: createIncrementAsyncAction,
  }
)(CountUI)
